package com.atguigu.admin.exception;

/**
 * @author 杨林
 * @create 2023-08-31 9:42 星期四
 * description:
 */

import lombok.SneakyThrows;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义异常解析器
 */
@Order(value = Ordered.HIGHEST_PRECEDENCE)   //拥有最高优先级（数字越小，优先级越高）
@Component
public class CustomerHandlerExceptionResolver implements HandlerExceptionResolver {
    @SneakyThrows
    @Override
    public ModelAndView resolveException(HttpServletRequest request, 
                                         HttpServletResponse response, 
                                         Object handler, 
                                         Exception ex) {
        response.sendError(511,"我喜欢的错误！！！！");
        return new ModelAndView();
    }
}
